package com.xiangyang.controller;

import com.xiangyang.annotations.OperationLog;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.entity.vo.ChagePwdInfo;
import com.xiangyang.entity.vo.ForgetPwdInfo;
import com.xiangyang.entity.vo.RegisterInfo;
import com.xiangyang.entity.vo.UserDetailInfo;
import com.xiangyang.service.impl.UserServiceImpl;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class LoginController {
    @Autowired
    private UserServiceImpl userService;
    @PostMapping("/login")
    @OperationLog(title = "登录", businessType = "登录系统")
    public Result login(@RequestBody UserDetailInfo userDetailInfo) {
        return userService.login(userDetailInfo.getUserPhone(), userDetailInfo.getUserPassword());
    }
    @GetMapping("/logout")
    public Result logout(HttpServletRequest request, HttpServletResponse response) {
        return userService.logout(request, response);
    }
    @PostMapping("/register")
    public Result register(@RequestBody RegisterInfo registerInfo) {
        return userService.register(registerInfo);
    }
    @PostMapping("/forgetPassword")
    public Result ForgotPassword(@RequestBody ForgetPwdInfo forgetPwdInfo) {
        return userService.forgetPassword(forgetPwdInfo);
    }
    @PostMapping ("/getCode")
    public Result getCode(@RequestParam("phone") String phone) {
        return userService.getCode(phone);
    }
    @PostMapping("/changePwd")
    public Result changePwd(@RequestBody ChagePwdInfo chagePwdInfo) {
        return userService.changePwd(chagePwdInfo);
    }


}
